<template>
  <div class="register">
    <van-nav-bar left-arrow @click-left="onClickLeft" />
    <div class="header">
      <h1>注册爱坤账号</h1>
      <p>系统会根据您选择的国家/地区的法律法规存储您的个人信息</p>
    </div>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="userName"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <van-checkbox v-model="checked" class="checked"
        >已阅读并同意爱坤帐号 用户协议 和 隐私政策</van-checkbox
      >
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit">注册</van-button>
        <p class="denglu" @click="denglu">已有账号?去登录</p>
      </div>
    </van-form>
  </div>
</template>

<script>
import { reqRegister } from "../../api/user";
import { Toast } from "vant";

export default {
  data(){
    return {
      username:"",
      password:"",
      checked:false,
    };
  },
  methods: {
    denglu(){
      this.$router.push("/login");
    },
    onClickLeft() {
      // Toast("返回");
      this.$router.go(-1);
    },
    async onSubmit(values){
      console.log("submit",values);
      const result=await reqRegister({...values,avatar:this.imgurl});
      console.log(result);
      if(this.checked==false){
        Toast("请勾选用户协议");
      }else if(result.code=="error"){
        Toast(result.message);
      }else if(result.code=="success"){
        this.$router.push("/login")
      }
    }
  },
};
</script>

<style scoped>
/* @import '../../../public/css/reset.css'; */
.header{
  margin: 16px;
}
.header h1{
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 20px;
}
.header p{
  font-size: 11px;
  color: #0b84ff;
}
.checked{
  font-size: 13px;
  margin: 15px 0px 15px 16px;
}
.denglu{
  text-align: center;
  font-size: 10px;
  margin-top: 20px;
}
</style>
